package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by LENOVO on 2018/6/24.
 */
public class DBConnection {

    public Connection getDBconnection() throws Exception {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection= DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC",
                    "root",
                    "123456");
            return connection;
    }

    public static void main(String[] args) {
        DBConnection dbConnection = new DBConnection();
        Connection connection = null;
        try {
            connection = dbConnection.getDBconnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(connection != null) {
            System.out.println("数据库连接成功");
        }else {
            System.out.println("数据库连接失败");
        }
    }
}
